//
//  Study.swift
//  JiaoZiTaxi
//
//  Created by Hu Gang on 2022/10/9.
//

import SwiftUI

struct StudyView: View {
  @ObservedObject var user : User
  @State var showSon : Bool = false
  var body: some View {
    VStack {
      VStack {
        Text("1:\(user.firstName) \(user.lastName)")
        TextField("First Name", text: $user.firstName).border(.black).padding()
        TextField("Last Name", text: $user.lastName).border(.black).padding()

        Button {
          showSon = true
        } label: {
          Text("Show Son View")
        }.sheet(isPresented: $showSon) {
          SonView(user: user)
        }

      }.padding()




    }
  }
}

struct SonView:View {
  @ObservedObject var user : User
  @Environment(\.dismiss) var dismiss
  var body: some View {
      VStack {
        Text("2:\(user.firstName) \(user.lastName)")
        TextField("First Name2", text: $user.firstName).border(.black).padding()
        TextField("Last Name2", text: $user.lastName).border(.black).padding()

        Button {
          user.firstName = "Hello"
          user.lastName = "World"
        } label: {
          Text("HelloWorld")
        }

        Button {
          dismiss()
        } label: {
          Text("Close me")
        }


      }.padding()

  }
}

class User : ObservableObject {
  @Published var firstName : String = ""
  @Published var lastName : String = ""
}

struct Study_Previews: PreviewProvider {
    static var previews: some View {
      StudyView(user: User())
    }
}
